package com.yonghui.springsecurityoauth2demo.exception;


import com.yonghui.springsecurityoauth2demo.pojo.ResultCode;
import com.yonghui.springsecurityoauth2demo.pojo.ResultVo;
import com.yonghui.springsecurityoauth2demo.utils.ResponseUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 公众号：码猿技术专栏
 *
 * TOKEN失效或者校验失败的处理器
 */
@Component

public class OAuthResourceAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
        //TODO token失效提示
        ResponseUtils.result(response,new ResultVo(ResultCode.TOKEN_ERROR.getCode(),ResultCode.TOKEN_ERROR.getMsg(),null));
    }
}